package com.moyq5.permit.center.web.jackson.filter;

import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;

import com.moyq5.mvc.framework.utils.StringUtils;
import com.moyq5.permit.center.bean.entity.Charge;
import com.moyq5.permit.center.bean.entity.Charge_;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;

/**
 * @author Moyq5's MvcMaker Tools
 */
public abstract class ChargeFilter {

	public static FilterProvider get(String filter) {
		if (StringUtils.isEmpty(filter)) {
			return get();
		}
		try {
			Method method = ChargeFilter.class.getMethod("getWith" + String.valueOf(filter.charAt(0)).toUpperCase() + filter.substring(1));
			return (FilterProvider)method.invoke(null);
		} catch (Exception e) {
			return get();
		}
	}
	
	public static Set<String> baseFields() {
		final Set<String> charge = new HashSet<String>();
		charge.add(Charge_.CHARGE_ID);
		charge.add(Charge_.CHANNEL_CODE);
		charge.add(Charge_.AMOUNT);
		charge.add(Charge_.ORDER_TIME);
		charge.add(Charge_.MOBILE);
		charge.add(Charge_.ORDER_NO);
		charge.add(Charge_.STATUS);
		return charge;
	}

	public static FilterProvider getId() {
		final Set<String> charge = new HashSet<String>();
		charge.add(Charge_.CHARGE_ID);
		
		return new SimpleFilterProvider().addFilter(
				Charge.class.getSimpleName(),
				SimpleBeanPropertyFilter.filterOutAllExcept(charge));
	}

	public static FilterProvider get() {
		return new SimpleFilterProvider().addFilter(
				Charge.class.getSimpleName(),
				SimpleBeanPropertyFilter.filterOutAllExcept(baseFields()));
	}

}
